-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat: make handleFetch
a shared hook
#13755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 767c555 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
195ccbd
to
9b4bb44
Compare
Nobody wants to review ? |
Thanks for the PR! The team will have to discuss this first and it might be better to do so in an issue beforehand. |
9b4bb44
to
0b0bfc9
Compare
0b0bfc9
to
767c555
Compare
Hi, @eltigerchino, I understand your will to discuss about this feature first. In fact, I was blocked on a project for this reason and I thought that it would be the most reliable solution to encapsulate I still think that making I'm welcome to open discussion and see how I can help. PS: I rebased my branch on top of main to resolve conflicts |
Hello Svelte Team,
I send you this PR to make
handleFetch
a shared hook that can be used on both client and server side.Motivation
I'm working a hybrid client/server administration portal where authentication is done using
OAuth
/OIDC
+JWT
tokens. I'm trying to create a secure and performant authentication process and I noticed that we could create something very powerful with SvelteKit by improving some features.Indeed, a good practice when working on a SSR environment is:
access token
andrefresh token
to clientrefresh token
on a cookie (not the access token)However, on a very hybrid scenarios where requests are done sometimes on the client, sometimes on the server, it multiplies the numbers of refresh token requests and create a bottleneck on the auth server.
So a good improvement would be to constantly pass the access token from the client to the server to allow reusing during the session. I noticed that we can take control of
fetch
requests on the server side but not on the client side.Other use cases
I see some scenarios where controling the client-side
fetch
would be useful:load
andaction
functionsImplementation
This PR replicates the behavior of the server-side
handleFetch
hook with one difference: the hook does not have access toevent
.Notes
I wanted to include a test similar to the server-side
handleFetch
. However I did not find any tests for server-sidehandleFetch
.I'm open to any idea to create tests for both hooks.
Edit : I finally found my way and included some tests, do not hesitate to review them!
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.Edits